﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.Supervise.Model;

namespace HZ.Supervise.Web.PageControl
{
    public partial class SortLeft : BasePage
    {
        string strhid = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["query"] = URLUtil.GetSuperviseQueryFromURL(Request);
                bangdingSort();
            }
        }

        protected void gvwselect_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvwselect.PageIndex = e.NewPageIndex;
            gvwselect.DataBind();
        }


        /// <summary>
        /// 绑定企业
        /// </summary>
        private void bangdingSort()
        {

            HZ.Supervise.IBLL.IBLL_ProcureCatalog pre = HZ.Supervise.BLLFactory.IBLL_ProcureCatalog();
            string _srortname = txtname.Text.Trim();
            int outcount;
            DataTable dt = pre.GetSort(_srortname, AspNetPager1.CurrentPageIndex,AspNetPager1.PageSize, out outcount);
            AspNetPager1.RecordCount = outcount;
            gvwselect.DataSource = dt;
            gvwselect.DataBind();
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            bangdingSort();
        }

        protected void rblcompanytype_SelectedIndexChanged(object sender, EventArgs e)
        {
            bangdingSort();
        }

        protected void gvwselect_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string sessionid = Guid.NewGuid().ToString();
                SuperviseQuery query = (SuperviseQuery)ViewState["query"];
                query.SortName = e.Row.Cells[0].Text.Trim();
                Session[sessionid] = query;
                e.Row.Cells[0].Text = "<a  style=\"cursor:hand\" onclick=\"seturl('" + sessionid + "')\">" + e.Row.Cells[0].Text + "</a>";

            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bangdingSort();
        }

        protected void btnQuery_Click(object sender, ImageClickEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            bangdingSort();
        }
    }
}
